﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Correios.Net;
using ProjetoSolo.QueroGas.Aplicacao.ServicosExternos;
using ProjetoSolo.QueroGas.Dominio.Entidades;

namespace ProjetoSolo.QueroGas.Infraestrutura.ServicosWeb
{
    public class ServicoWebBuscaEndereco : IServicoBuscaEndereco
    {
        public Endereco BuscarPorCep(string cep)
        {
            this.AjustarCabecalhoHttpServico();

            Address endereco = BuscaCep.GetAddress(cep);

            return this.ConverterAddressParaEndereco(endereco);
        }

        private void AjustarCabecalhoHttpServico()
        {
            System.Net.ServicePointManager.Expect100Continue = false;
        }

        private Endereco ConverterAddressParaEndereco(Address address)
        {
            Endereco endereco = new Endereco(address.Cep, address.State, address.City, address.District, address.Street, "", 1, 1);
            return endereco;
        }
    }
}
